#include "CF_Includes.h"

CCF_Log::CCF_Log()
{
  this->m_fEnable;
}

CCF_Log::~CCF_Log()
{
}

CCF_Log* CCF_Log::pInstance = NULL;

CCF_Log* CCF_Log::getClassLog(void)
{
	if(pInstance == 0)
	{
		pInstance = new CCF_Log();
		pInstance->BeginLogging();
	}
	return pInstance;
}

//-----------------------------------------------------------------------------
// Name: XLogError(char *lpszText, ...)
// Desc: Logging
//-----------------------------------------------------------------------------
void CCF_Log::LogError(char *lpszText, ...)
{
	if(m_fEnable)
	{
		va_list argList;
		FILE *pFile = NULL;

		//Initialize variable argument list
		va_start(argList, lpszText);

		//Open the log file for appending
		pFile = fopen("XPowerLog.htm", "a+");

		if(pFile != NULL)
		{
			//Write the error to the log file
			fprintf(pFile, "<font face=\"Arial\" size=\"2\" color=\"#FF0000\"><b>");
			vfprintf(pFile, lpszText, argList);
			fprintf(pFile, "</b></font><br>\n");

			//Close the file
			fclose(pFile);
		}

		va_end(argList);
	}
}
//-----------------------------------------------------------------------------
// Name: XWriteToLog(char *lpszText, ...)
// Desc: Logging
//-----------------------------------------------------------------------------
void CCF_Log::WriteToLog(char *lpszText, ...)
{
	if(m_fEnable)
	{
		va_list argList;
		FILE *pFile = NULL;

		//Initialize variable argument list
		va_start(argList, lpszText);

		//Open the log file for appending
		pFile = fopen("XPowerLog.htm", "a+");

		if(pFile != NULL)
		{
			//Write the error to the log file
			fprintf(pFile, "<font face=\"Arial\" size=\"2\" color=\"#000000\">");
			vfprintf(pFile, lpszText, argList);
			fprintf(pFile, "</font><br>\n");

			//Close the file
			fclose(pFile);
		}

		va_end(argList);
	}
}
//-----------------------------------------------------------------------------
// Name: XLogWarning(char *lpszText, ...)
// Desc: Logging
//-----------------------------------------------------------------------------
void CCF_Log::LogWarning(char *lpszText, ...)
{
	if(m_fEnable)
	{
		va_list argList;
		FILE *pFile = NULL;

		//Initialize variable argument list
		va_start(argList, lpszText);

		//Open the log file for appending
		pFile = fopen("XPowerLog.htm", "a+");

		if(pFile != NULL)
		{
			//Write the error to the log file
			fprintf(pFile, "<font face=\"Arial\" size=\"2\" color=\"#E7651A\"><b>");
			vfprintf(pFile, lpszText, argList);
			fprintf(pFile, "</b></font><br>\n");

			//Close the file
			fclose(pFile);
		}

		va_end(argList);
	}
}
//-----------------------------------------------------------------------------
// Name: XBeginLogging()
// Desc: Logging
//-----------------------------------------------------------------------------
void CCF_Log::BeginLogging()
{
	FILE* pFile = NULL;

	//OPen the file and clear the contents
	pFile = fopen("XPowerLog.htm", "wb");

	if(pFile != NULL)
	{
		//Write start html to log
		fprintf(pFile, "<html><head><title>Log File</title></head><body>\n");
		fprintf(pFile, "<font face=\"Arial\" size=\"4\" color=\"#000000\"><b><u>Log File</u></b></font><br>\n");

		//Close the file
		fclose(pFile);

		m_fEnable = true;
	}
}
//-----------------------------------------------------------------------------
// Name: XEndLogging()
// Desc: Logging
//-----------------------------------------------------------------------------
void CCF_Log::EndLogging()
{
	if(m_fEnable)
	{
		FILE *pFile = NULL;

		//Open the log file for appending
		pFile = fopen("XPowerLog.htm", "a+");
		
		if(pFile != NULL)
		{
			//Write end html to log
			fprintf(pFile, "</body></html>");

			//Close the file
			fclose(pFile);
		}

		m_fEnable = false;
	}
}


